package org.mch.func.file.content;

import java.awt.event.ActionEvent;
import java.io.File;

import org.mch.biz.ui.FuncEvent;
import org.mch.biz.ui.FuncPanel;

/**
 * 描述：文件操作；
 * 
 * @author MCH；Date：2008-10-01；<BR/>
 * 
 */
public class ClientEvent extends FuncEvent {
	private static final long serialVersionUID = -8590108060646853821L;

	public ClientEvent(FuncPanel panel) {
		super(panel);
	}

	protected void onButtonClick(ActionEvent e) throws Exception {
		if (e.getSource() == getPanel().getBtnExecute()) {
			execute();
		}
	}

	public void execute() {
		File file = new File(getPanel().getFile_path().getValue());
		String patternText = getPanel().getTextRegex().getText();
		String repAfterText = getPanel().getTextRepText().getText();

		if (file.isDirectory()) {
			File[] files = file.listFiles();
			ContentRegexRep crr = new ContentRegexRep();
			for (File f : files) {
				try {
					crr.regexRep(f, patternText, repAfterText);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}

	public ClientPanel getPanel() {
		return (ClientPanel) super.getPanel();
	}
}